<!--
 * @Description: 代理购票
 * @Version: 2.0
 * @Autor: 许国辉
 * @Date: 2022-12-13 13:00:56
 * @LastEditors: 许国辉
 * @LastEditTime: 2023-10-21 20:08:02
-->
<template>
  <div>等待进入...</div>

  <div v-if="htmlStr">
    <a :href="htmlStr" target="_blank">go </a>
    <!-- <div v-html="htmlStr"></div> -->
  </div>
  <!-- <iframe
    :src="htmlStr"
    scrolling="auto"
    frameborder="no"
    style="width: 100%; height: 460px"
    target="_top"
  ></iframe> -->
</template>
<script setup lang="ts">
  import { onMounted, ref } from 'vue';
  import { oaLoginNew, oaLoginPW } from '../../api/sys/appSettingApi/appNotificationAPI';
  import { useTabs } from '/@/hooks/web/useTabs';
  import { useRouter } from 'vue-router';
  // import axios from 'axios';
  const { currentRoute } = useRouter();
  const { close } = useTabs();
  const htmlStr = ref('');
  const goLoginTicket = async () => {
    await oaLoginNew({
      direction: 'WEB',
      homePage: 'air',
      userID: '189427575657857024',
    }).then(async (dataLogin) => {
      window.open(dataLogin);
      await oaLoginPW().then((data: any) => {
        // axios({
        //   method: 'POST',
        //   url: 'https://openapi.baiyunair.com/open/api/login/oaLogin',
        //   headers: {
        //     'Content-Type': 'application/x-www-form-urlencoded',
        //   },
        //   params: {
        //     vouchered: data.vouchered,
        //     timestamp: data.timestamp,
        //     bkcid: data.bkcid,
        //     emnum: data.emnum,
        //     isDisplayTW: true,
        //     sign: data.sign,
        //   },
        // }).then(async function (vH: any) {
        //   htmlStr.value = JSON.stringify(vH);
        //   // window.open(JSON.stringify(vH));
        // });
        let str =
          'https://openapi.baiyunair.com/open/api/login/oaLogin?vouchered=' +
          data.vouchered +
          '&timestamp=' +
          data.timestamp +
          '&bkcid=' +
          data.bkcid +
          '&emnum=' +
          data.emnum +
          '&isDisplayTW=true&sign=' +
          data.sign;
        htmlStr.value = str;

        // setTimeout(() => {
        //   window.open(str);
        // }, 200);
      });

      setTimeout(async () => {
        close(currentRoute.value);
        // tabStore.refreshPage(router);
      }, 6000);
      //
    });
  };

  onMounted(() => {
    setTimeout(() => {
      goLoginTicket();
    }, 30);
  });
</script>
